fix: Workflow start time and time zone error#4011
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| return {'time': timezone.localtime(timezone.now()).strftime('%Y-%m-%d %H:%M:%S'), 'start_time': time.time(), | ||
| 'history_context': history_context, 'chat_id': str(chat_id), **node.workflow_manage.form_data, | ||
| 'chat_user_id': body.get('chat_user_id'), | ||
| 'chat_user_type': body.get('chat_user_type'), |
There was a problem hiding this comment.
The provided code snippet contains a couple of improvements that I would suggest:
-
Use
datetimeinstead oftime: The original code usestimezone.now()followed by.strftime(), which returns an ISO-formatted string. However, it's typically better to usedatetime.datetime.now()with appropriate timezone handling if needed. -
Add type hints for arguments and variables: This can help clarify the expected types, making the function more maintainable and robust.
Here's the revised version:
import datetime
from django.utils import timezone
def get_global_variable(node) -> dict:
# Assuming history_chat_record is defined elsewhere
history_context = [
{
"question": chat_record.problem_text,
"answer": chat_record.answer_text
}
for chat_record in history_chat_record
]
chat_id = node.flow_params_serializer.data.get('chat_id')
current_datetime = timezone.localtime(timezone.now())
start_time = time.time()
return {
'time': current_datetime.strftime('%Y-%m-%d %H:%M:%S'),
'start_time': start_time,
'history_context': history_context,
'chat_id': str(chat_id),
**node.workflow_manage.form_data,
'chat_user_id': body.get('chat_user_id'),
'chat_user_type': body.get('chat_user_type'),
}These changes should make the code cleaner and potentially faster due to avoiding explicit conversion from one format to another unnecessarily.
fix: Workflow start time and time zone error